import { createApp ,type App as AppType} from 'vue'
import './style.css'
import App from './App.vue'
import { createPinia } from 'pinia';
import router from './router';
import { renderWithQiankun, qiankunWindow, type QiankunProps} from 'vite-plugin-qiankun/dist/helper'
import { log } from 'console';

let app: AppType<Element>;

const initQiankun = () => {
  renderWithQiankun({
    mount(props: QiankunProps) {
      const { container } = props;
      render(container);
    },
    bootstrap: function (): void | Promise<void>{
      console.log('bootstrap')
    },
    unmount: function (props: QiankunProps): void | Promise<void>{
      app.unmount();
    },
    update: function (props: QiankunProps): void | Promise<void>{
      console.log('update')
    }
  })
}

const render = (container?: Element | undefined) => {
  app = createApp(App);
  app.use(createPinia()).use(router).mount(container ? container.querySelector('#app')! : '#app')
}

qiankunWindow.__POWERED_BY_QIANKUN__ ? initQiankun() : render();
// createApp(App).mount('#app')
